package servlet;

import model.Goods;
import model.User;
import service.GoodsService;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "history_goods_publish", urlPatterns = "/history_goods_publish")
public class HistoryGoodsPublishServlet extends HttpServlet  {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User) request.getSession().getAttribute("user");
        GoodsService goodsService = new GoodsService();
        // 得到参数is_removed
        int is_removed = Integer.parseInt(request.getParameter("is_removed"));
        List<Goods> list = null;
        if(is_removed == 1) {
            list = goodsService.GetIsRemovedProducts(user.getId(), true);
        }
        else if(is_removed == 0) {
            list = goodsService.GetNotRemovedProducts(user.getId(), false);
        }
        else if(is_removed == 2) {
            list = goodsService.GetProductsByUserId(user.getId());
        }

         request.setAttribute("publishGoodsList", list);


        request.getRequestDispatcher("/history_goods_publish.jsp").forward(request, response);
    }
}